package edu.cqie.smartfarm.exception.handler;

import edu.cqie.smartfarm.exception.annotation.GlobalException;
import edu.cqie.smartfarm.exception.exception.IGlobalException;
import edu.cqie.smartfarm.result.R;
import edu.cqie.smartfarm.result.ResultCodeEnum;
import lombok.extern.slf4j.Slf4j;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 运行时异常
 *
 * @author shineTan
 * @date 2023/01/13 11:11
 */
@Slf4j
@GlobalException(throwable = RuntimeException.class)
public class RuntimeExceptionHandler implements IGlobalException<R, RuntimeException> {

    @Override
    public R exception(RuntimeException throwable, HttpServletRequest request, HttpServletResponse response) {
        log.error(throwable.getMessage(), throwable);
        return R.Failed(ResultCodeEnum.SYSTEM_EXCEPTION.getCode(), throwable.getMessage());
    }
}
